//
//  PYProgressView.swift
//  ltsp
//
//  Created by PerhapYs on 2022/6/29.
//

import UIKit

class PYProgressView: UIView {
    
    var progressColor : UIColor = UIColor.white{
        didSet{
            self.progreeView.backgroundColor = progressColor
        }
    }
    
    var percent : CGFloat = 0{
        
        didSet{
            
            UIView.animate(withDuration: 0.2) { [percent] in
                
                self.progreeView.snp.remakeConstraints { make in
                    make.left.top.bottom.equalToSuperview()
                    make.width.equalToSuperview().multipliedBy(percent)
                }
                self.layoutIfNeeded()
            }
        }
    }

    init(){
        super.init(frame: .zero)
        
        self.addSubview(self.progreeView)
        self.progreeView.snp.makeConstraints { make in
            make.left.top.bottom.equalToSuperview()
            make.width.equalTo(0)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var progreeView: UIView = {
        
        return UIView()
    }()
}
